<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>学生reviewbook下载记录管理</title>
<meta name="decorator" content="default"/>
<script src="${ctxStatic}/jquery-tool/table2excel/js/base64.js"></script>
<script src="${ctxStatic}/jquery-tool/table2excel/js/table2excel.js" type="text/javascript"></script>

<script type="text/javascript">
	//url
	var listUrl = '${ctx}/curriculum/studentReviewbookInfo/';
	var cardUrl = '${ctx}/curriculum/studentReviewbookInfo/form';
	var sortUrl = listUrl+'updateSort';
	var statusUrl = listUrl+"ajaxUpdateStatus";
	var cumcoreDomain = '${domain2}';
	var currciculumDomain = '${domain}';
	var apiPrefix = '${apiPrefix}';
	
	$(document).ready(function() {
	
	});
	function openUrl(obj){
		if (obj != null) { //单个删除
			var curentTr = jQuery(obj).parents('ol')[0];
			var vUrl = jQuery('[attrname="url"]', curentTr).html();
			if(vUrl!=null && vUrl !=''){
				window.open(vUrl, '_blank').location;
				
				
			}
		}
	}
	function openUrl2(obj){
		if (obj != null) { //单个删除
			var curentTr = jQuery(obj).parents('ol')[0];
			var vUrl = jQuery('[attrname="url"]', curentTr).html();
			if(vUrl!=null && vUrl !=''){
				
				var Url2 = cumcoreDomain+apiPrefix +'/'+vUrl.substring(vUrl.indexOf(apiPrefix)+1);
				window.open(Url2, '_blank').location;
			}
		}
	}
	
</script>
<style type="text/css">
.tableHead th, td {
	text-align: center;
}
body{
	background-color: #f5f5f5;
}

</style>
</head>
<body>

	<div class="breadcrumb form-search"  style="margin: 50px;">
		<%-- <div class="control-group" >
			<label class="control-label">服务:</label>
			<select id="serverType" name="serverType" class="input-medium required" value='${serverType}'>
				<option value="aws">课程cum</option>
			</select>
		</div> --%>
		<div class="control-group" >
			<label class="control-label">服务信息列表：</label>
			<div class="controls">
				<textarea id="urls" style="width:700px;height: 100px; border: 1px solid #ddd;overflow-y: auto;" >
				</textarea>
				<br><br>
				<input id="btnFreshCDN" class="btn btn-primary" type="button" value="查 询" onclick="clearCache(this)">
				&nbsp;
				<input id="btnFreshClear" class="btn " type="button" value="清除" onclick="clearUrls()">
				<input id="btnFreshClear2" class="btn " type="button" value="导出Excel" onclick="exportExcel('tableServerId')">
			</div>
		</div>
		<div class="control-group" >
			<label class="control-label">注：</label>
			<div class="controls">
				<span class="help-inline"><font color="red">
				key为  服务ip或者服务名称 
				常用值：10.23.17.118 ,l-cum-core-server17.ec.prod.aws.dm
				<br>
				
				</font> </span>
			</div>
		</div>
		<br>
		<div class="control-group" >
			<label class="control-label">服务信息：</label>
			<div class="controls">
				<div id="docListId" style="width:1200px;min-height: 500px; border: 0px solid #ddd;overflow-y: auto;">
					<table id= "tableServerId" class="showTable table table-striped table-bordered table-condensed">
						<thead>
							<tr class="tableHead" id="trHeadId">
								<th style="text-align:center;" onclick="toggleCheckBox('checkboxName',this)">
						  			<input type="checkbox" checkboxName="sort" name="table_form_checkbox_all" value="">
						  		</th>
						  		<th class="sort" style="text-align:center;">序号</th>
						  		<th class="sort" style="width: 400px;">实例名</th>
						  		<th class="sort" style="width: 30px;">状态</th>
						  		<th class="sort">内网IP</th>
								<th class="sort">公网IP</th>
								<th class="sort">配置</th>
								<th class="sort">创建用户</th>
								<th class="sort">平台类型</th>
								<th class="sort">区域</th>
								<th class="sort">可用区</th>
							</tr>
						</thead>
						<tbody id="dataBodyId">
							
						</tbody>
						<tbody  style="display: none;">
							<tr id="testTrId">
								<td style="text-align:center;" >
									<input type="checkbox" name="sort" attrname="sort" value="">
								</td>
								<td style="text-align:center;">
									<span attrname="number">1</span>
								</td>
								<td class="td2"><span class="trvalue" attrname="hostname"></span></td>
								<td class="td2"><span class="trvalue" attrname="status"></span></td>
								<td class="td2"><span class="trvalue" attrname="private_ip"></span></td>
								<td class="td2"><span class="trvalue" attrname="public_ip"></span></td>
								<td class="td2"><span class="trvalue" attrname="cpu_core_num"></span>核 <span class="trvalue" attrname="mem"></span>G</td>
								<td class="td2"><span class="trvalue" attrname="create_user"></span></td>
								<td class="td2"><span class="trvalue" attrname="platform"></span></td>
								<td class="td2"><span class="trvalue" attrname="region"></span></td>
								<td class="td2"><span class="trvalue" attrname="zone"></span></td>
							</tr>
						</tbody>
					</table>
				</div>
		</div>
		</div>
	</div>
	
	<div style="height: 50px;width: 100%;"></div>
	<script type="text/javascript">
	//URL
	var listUrl = '${ctx}/server/';
	
	var leftWidth = 180; // 左侧窗口大小
	var htmlObj = $("html"), mainObj = $("#main");
	var frameObj = $("#left, #openClose, #right, #right iframe");
	function wSize(){
		 var strs = getWindowSize().toString().split(",");
		//htmlObj.css({"overflow-x":"hidden", "overflow-y":"hidden"});
		mainObj.css("width","auto");
		frameObj.height(strs[0] - 5);
		var leftWidth = ($("#left").width() < 0 ? 0 : $("#left").width());
		$("#right").width($("#content").width()- leftWidth - $("#openClose").width() -5);
		$(".ztree").width(leftWidth - 10).height(frameObj.height() - 46); 
	}

	
	var serverType = '${serverType}';
	$(document).ready(function() {
		/* var serverTypeObj = jQuery('#formAreaId').find('[name="serverType"]');
		serverTypeObj.val(serverType);
		serverTypeObj.select2();
		serverTypeObj.css('display', 'none');
		serverTypeObj.attr("disabled", true); */
		
	});
	function refresh(){
		var url = "/server/index";
		url +="?serverType="+serverType;
		window.location = url;
	}

	function clearUrls(){
		jQuery('#urls').val(null);
	}
	function clearCache(obj){
		
		var urlsText = jQuery('#urls').val();
		//debugger;
		if(urlsText!=null && urlsText != ''){
			var st = urlsText.replace(new RegExp('\n', "gm"), ',');
			var st1 = st.replace(new RegExp(' ', "gm"), ',');
			var arrays = st1.split(',');
			
			//var arrays = urlsText.split('\n');
			if(arrays!=null && arrays.length >0){
				
				var keys = [];
				var flag = true;
				var message = "";
				for (var i = 0; i < arrays.length; i++) {
					var fileUrl =  arrays[i];
					if(fileUrl!=null && fileUrl!=''){
						var key1 = jQuery.trim(fileUrl);
						if(key1 != ''){
							keys.push(key1);
						}
					}
				}
				if(flag &&( keys.length >0 || keys.length >0 )){
					ajaxClearCacheByKeys(keys.join(','));
				}else{
					if(message ==null || message==''){
						message = '请输入有效key';
					}
					alertx(message);
				}
			}
		}else{
			alertx('请输入key');
		}
	}
	
	
	function ajaxClearCacheByKeys(keys){
		var url = listUrl + 'findServersByInfo?rk='+Math.random();
		var data = {info : keys};
	    jQuery.ajax({  
			url: url, async : false,type: "POST",
			data : data,
			success: function(response) {
				info = response;
				console.log(info);
				if(info!=null){
					if(info.status == 1){
						var res = info.data;
						if(res!=null){
							var datas = res.list;
							loadTable(datas);
							
						}
					}else{
						alertx(info.message);
					}
				}
			},
			error: function(e){console.error(e);}
		});
	}
	
	function loadTable(datas){
		if (datas == null || datas.length == 0) { 
			
			return ;
		}
		var demoTr = jQuery('#testTrId');
		var dataBody = jQuery('#dataBodyId');
		dataBody.html(null);
		dataBody.hide();
		var trs = [];
		for (var i = 0; i < datas.length; i++) {
			var number = i+1;
			var data = datas[i];
			var demoTr0 = demoTr.clone();
			jQuery('[attrname="number"]',demoTr0).html(number);
			jQuery('[attrname]',demoTr0).each(function(){
				var attrname = jQuery(this).attr("attrname");
				var value = data[attrname];
				jQuery(this).html(value);
			});
			
			dataBody.append(demoTr0);
		}
		dataBody.show();
	}
	
	function exportExcel(tableId){
		$("#"+tableId).table2excel({    
			// 不被导出的表格行的CSS class类
	    exclude: ".noExl",
	    // 导出的Excel文档的名称
	     name: "表格-" + new Date().getTime(),
	     // Excel文件的名称
	     filename: "表格-" + new Date().getTime() + ".xlsx",
	     bootstrap: false
        });   
	}

	window.onload = function() {
		loadSortRow();
	}
	
	function loadSortRow(){
		var HeadTD = document.getElementById("trHeadId");
		var ContTD = document.getElementById("dataBodyId");
		var HeadList = HeadTD.getElementsByTagName("th");
		var ContTrList = ContTD.getElementsByTagName("tr");
		var sortArray = new Array();
		var newNode;
		for(var i = 0; i < HeadList.length; i++) {
			HeadList[i].index = i;
			HeadList[i].onclick = function() {
				if(this.className) {
					newNode = "";
					try{
						for(var j = 0; j < ContTrList.length; j++) {
							sortArray[j] = new Array();
							sortArray[j][0] = ContTrList[j].getElementsByTagName("td")[this.index].innerText;
							sortArray[j][1] = j;
						}
						
						if(!isNaN(sortArray[0][0])){
							sortArray.sort(sortNumber);
						}else{
							sortArray.sort();
						}
						for(var x = 0; x < ContTrList.length; x++) {
							if(ContTrList[sortArray[x][1]] == null || ContTrList[sortArray[x][1]].innerHTML == null){
								continue;
							}
							var html = ContTrList[sortArray[x][1]].innerHTML;
							newNode += "<tr>" + html  + "</tr>";
						}
		 
						ContTD.innerHTML = newNode;
						
					}catch(e){
						console.log("排序出错 ",e);
					}
				}
			}
		}
	}
	
	function sortNumber(a1, b1) {
		var a = a1;
		var b = b1;
		try {
			a = parseInt(a1);
		} catch (e) {
			
		}
		try {
			b = parseInt(b1);
		} catch (e) {
			
		}
		if(a > b) {
			return 1
		} else if(a < b) {
			return -1
		} else {
			return 0
		}
	}
	
	
	</script>
</body>
</html>